<?php

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Backoffice\Model\Entity\Produit;
use Zend\View\Model\ViewModel;

class BoutiqueController extends AbstractActionController
{
    protected $em;
    public function getEntityManager()
    {
        if (null === $this->em) {
            $this->em = $this->getServiceLocator()
                ->get('doctrine.entitymanager.orm_default');
        }
        return $this->em;
    }
    public function indexAction()
    {
        
        $id = $this->params()->fromRoute('id');
        if($id == null) {
            header('Location: /');
            exit;
        }
        $boutique = $this->getEntityManager()->getRepository('Backoffice\Model\Entity\Boutique')->find($id);
                
        $qb = $this->getEntityManager()->createQueryBuilder();
        $qb->select('p')
           ->from('Backoffice\Model\Entity\Produit', 'p')
           ->where('p.boutique = :boutique')
           ->andWhere('p.etat != 3');
        $qb->setParameters(array('boutique' => $id));
        
        $query = $qb->getQuery();
        $produits = $query->getResult();
                 
         $moduleConfig = $this->getServiceLocator()->get('config');
        $file_path = $moduleConfig['application']['file_path'];
        $full_file_path = $moduleConfig['application']['full_file_path'];
        
        return new ViewModel(
            array(
                'boutique' => $boutique,
                'produits' => $produits,
                'file_path' => $file_path,
                'full_file_path' => $full_file_path,
            )
        );
    }


}

